'use strict';


const BaseController = require('../base');
const JUtil = require('../../utils/JUtil');
const SessionUtil = require('../../utils/SessionUtil');
const RedisUtil = require('../../utils/RedisUtil');


class TestController extends BaseController {

    async index() {
        this.ctx.body = 'Test!!~~';
    }

    async getData() {
        let result = await this.ctx.service.api.test.getData();
        this.ctx.body = JUtil.P(0, result);
    }

    async setRedis() {
        // await this.app.redis.set('foo', 'bar');
        // await this.app.redis.set('name', 'zhangsan');
        await RedisUtil.set(this.app, 'nickname', 'Happy!!!!', 60);
        this.ctx.body = 'hello111';
    }

    async getRedis() {
        let nickname = await RedisUtil.get(this.app, 'nickname');
        let name = await RedisUtil.get(this.app, 'name');
        this.ctx.body = name + " === " + nickname;
    }

    async setSession() {

        await SessionUtil.set(this.ctx, 'test', 'hello world!!!');

        this.ctx.body = 'hehe';
    }

    async getSession() {

        let test = await SessionUtil.get(this.ctx, 'test');
        this.ctx.body = test;
    }

}

module.exports = TestController;


